package com.syj.usepagehelper.controller;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.syj.usepagehelper.mapper.QueryMapper;
import com.syj.usepagehelper.model.vo.request.PageRequest;
import com.syj.usepagehelper.model.vo.response.BaseResponse;
import com.syj.usepagehelper.model.vo.response.BaseResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
 * @ClassName : QueryOracleController
 * @Description :
 * @Author : 石蕴杰
 * @Date: 2020/6/28 20:32
 */
@Controller
@Api(value = "测试查询性能", tags = "测试查询性能")
@RequestMapping("/queryPerformance")
public class QueryOracleController {
    @Autowired
    QueryMapper queryMapper;
    @ApiOperation(value = "pageHelper方式查询")
    @PostMapping("/queryPageHelper")
    @ResponseBody
    public BaseResponse queryPageHelper(@RequestBody PageRequest pageRequest){
        PageHelper.startPage(900, 1000);
        long begintime = System.currentTimeMillis();
        List result = queryMapper.query(pageRequest);
        long endtime=System.currentTimeMillis();
        long costTime = (endtime - begintime);
        System.out.println("pageHelper方式查询耗时: "+costTime+" ms");
        PageInfo<List> pageInfo = new PageInfo<>(result);
        return BaseResponseUtil.success(pageInfo);
    }

}
